package com.jack.thinking.thread.core._2;

/**
 * one class 's all synchronized method handle one same the object
 * @author wangbingwu
 *
 */
public class SynchronizedBindObject {
	public static void main(String[] args) {
		MySynObject syn = new MySynObject();
		Thread t = new Thread() {
			@Override
			public void run() {
				try {
					syn.run();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		};
		t.start();
		
		Thread t1 = new Thread() {
			@Override
			public void run() {
				syn.stop();
			}
		};
		t1.start();
	}
}


class MySynObject{
	synchronized public void run() throws Exception {
		System.out.println("run --------");
		Thread.sleep(2000L);
	}
	
	synchronized public void stop() {
		System.out.println("stop -------");
	}
}